package com.shop.cereshop.app.dl.logic.utils;

import com.shop.cereshop.app.dl.logic.exception.ExceptionEnum;
import lombok.Data;

/**
 * @description 自定义返回值
 * @Author YF
 * @Date 日期:2021/4/12 时间:20:16
 */
@Data
public class ResultInfo<T> {
    private T data;
    private Integer code;
    private String message;

    public ResultInfo() {
        this.code = 200;
        this.message = "操作成功";
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public ResultInfo(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public static ResultInfo ok() {
        return new ResultInfo(200, "返回成功");
    }

    public static ResultInfo ok(String msg) {
        return new ResultInfo(200, msg);
    }

    public static ResultInfo error() {
        return new ResultInfo(400, "操作失败");
    }

    public static ResultInfo error(String msg) {
        return new ResultInfo(400, msg);
    }

    public static ResultInfo error(Integer code, String msg) {
        return new ResultInfo(code, msg);
    }

    public static ResultInfo error(ExceptionEnum exceptionEnum) {
        return new ResultInfo(exceptionEnum.getStatus(), exceptionEnum.getMessage());
    }

    public ResultInfo(T entity) {
        this.code = 200;
        this.message = "返回成功";
        this.data = entity;
    }


}
